const path=require("path");
const common=require("./webpack.common");
const { merge }=require("webpack-merge")
const MiniCssExtractPlugin=require("mini-css-extract-plugin") //CSS的按需加载 以link方式引入
const OptimizeCssAssetsWebpackPlugin=require("optimize-css-assets-webpack-plugin") //压缩css
const TerserWebpackPlugin=require("terser-webpack-plugin") //压缩js
const CopyWebpackPlugin=require("copy-webpack-plugin") //复制静态资源
const { CleanWebpackPlugin }  =require("clean-webpack-plugin") //清理文件
module.exports=merge(common,{
  mode:"production",
  optimization:{
    minimizer:[
      new OptimizeCssAssetsWebpackPlugin(),
      new TerserWebpackPlugin()
    ]
  },
  plugins:[
    new CleanWebpackPlugin(),
         new CopyWebpackPlugin({ //生产环境使用
              patterns: [
                  { from: path.resolve(__dirname,'./public'),
                     to:  path.resolve(__dirname,'dist')
                  },
                  { from: path.resolve(__dirname,'./src/assets'),
                      to: path.resolve(__dirname,'dist')
                 } 
              ],
        }),
        
  ]
})